cmake_minimum_required(VERSION 3.12.4)

# 设置项目名称
project(rtl8188eu)

if(NOT DEFINED CROSS_COMPILE_PATH)
    message(FATAL_ERROR "请在drivers目录下执行cmake命令！")
endif()

# 检查内核源码目录是否存在
if(NOT EXISTS ${KERNEL_SRC})
    message(FATAL_ERROR "内核源码目录 '${KERNEL_SRC}' 不存在，请检查KERNEL_SRC路径配置！")
endif()

# 设置编译选项
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCONFIG_PLATFORM_ARM_AM335X=y")

# 设置编译目标
add_custom_target(rtl8188eu_driver ALL
    COMMAND ${CMAKE_MAKE_PROGRAM}
        KSRC=${KERNEL_SRC}
        CROSS_COMPILE=${CROSS_COMPILE_PATH}/arm-arago-linux-gnueabi-
        ARCH=arm
        CONFIG_PLATFORM_ARM_AM335X=y
        modules
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rtl8188eu
    COMMENT "Building RTL8188EU driver module"
)

# 安装目标
#install(CODE "execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} KSRC=${KERNEL_SRC} INSTALL_MOD_PATH=${CMAKE_INSTALL_PREFIX} modules_install WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rtl8188eu)")